package quan.dong.object;

import quan.dong.common.Common;
import quan.dong.common.Constant;



public class PriceAlert {
	//total is 15 byte
	private String StockSymbol;//6byte
	private Boolean IsAbove;//1byte
	private float Price;//4 byte	
	private float CurrentPrice;//4 byte
	
	public String getStockSymbol() {
		return StockSymbol;
	}

	public void setStockSymbol(String stockSymbol) {
		StockSymbol = stockSymbol;
	}

	public Boolean getIsAbove() {
		return IsAbove;
	}

	public void setIsAbove(Boolean isAbove) {
		IsAbove = isAbove;
	}

	public float getPrice() {
		return Price;
	}

	public void setPrice(float price) {
		Price = price;
	}

	public float getCurrentPrice() {
		return CurrentPrice;
	}

	public void setCurrentPrice(float currentPrice) {
		CurrentPrice = currentPrice;
	}

	public boolean Serialize(byte[] bytes, int offset) throws Exception {
		Common.ConvertStringToByteArray(StockSymbol, bytes, offset);
		if(IsAbove)
			bytes[offset+6]=1;
		else
			bytes[offset+6]=0;
		Common.ConvertFloatToByteArray(Price, bytes, offset+7);
		Common.ConvertFloatToByteArray(CurrentPrice, bytes, offset+11);		
		return true;
	}

	public byte[] Serialize() throws Exception {
		byte[] buffer = new byte[Constant.SIZE_PRICE_ALERT];
		Serialize(buffer, 0);
		return buffer;
	}
	public boolean Deserialize(byte[] bytes, int offset) throws Exception {
		StockSymbol = new String(bytes, offset, 6).trim();
		if (bytes[offset+6] == 1) {
			IsAbove = true;
		} else {
			IsAbove = false;
		}
		Price=Common.ConvertByteArrayToFloat(bytes, offset+7);
		CurrentPrice=Common.ConvertByteArrayToFloat(bytes, offset+11);
		return true;
	}

	public boolean Deserialize(byte[] bytes) throws Exception {
		return Deserialize(bytes, 0);
	}
}
